import { Checkbox } from "antd";
import PropTypes from "prop-types";
const CheckboxComponent = (props) => {
  const onChange = (e) => {
    const isNumber = props.restype === "number";
    props.onChange && props.onChange(isNumber ? +e.target.checked : +e.target.checked);
  };

  const children = props.label && props.label[+props.value || 0];

  return (
    <Checkbox {...props} checked={!!props.value} onChange={onChange}>
      {children}
    </Checkbox>
  );
};
CheckboxComponent.propTypes = {
  value: PropTypes.any,
  onChange: PropTypes.func,
  label: PropTypes.array,
  restype: PropTypes.string,
};

export default CheckboxComponent;
